minetest.register_node("lunodecor:shieldblock_stone", {
	description = "Pedra Escudo",
	tiles = {"default_stone.png"},
	inventory_image = minetest.inventorycube("default_stone.png^text_shieldblock.png"),
	sounds = default.node_sound_stone_defaults(),
	drop = 'lunodecor:shieldblock_stone',
	groups = {cracky=3},
	walkable = false,
	after_place_node = function(pos, placer)
		local meta = minetest.get_meta(pos)
		meta:set_string("owner", placer:get_player_name() or "")
		--meta:set_string("infotext", "Ampola Vazia")
	end,
})

minetest.register_node("lunodecor:shieldblock_stone_tangible", {
	description = "Pedra Escudo",
	tiles = {"default_stone.png^text_shieldblock.png"},
	inventory_image = minetest.inventorycube("default_stone.png^text_shieldblock.png"),
	sounds = default.node_sound_stone_defaults(),
	drop = 'lunodecor:shieldblock_stone',
	--drawtype = "glasslike",
	--paramtype = "light",
	--paramtype2 = "flowingliquid",
	--sunlight_propagates = true,
	--alpha = WATER_ALPHA,
	groups = {cracky=3, stone=1, not_in_creative_inventory=1},
})

minetest.register_craft({
	output = 'lunodecor:shieldblock_stone',
	recipe = {
		{"default:stone"	,"default:paper"				,"default:stone"},
		{"default:paper"	,"lunorecipes:magicdust"	,"default:paper"},
		{"default:stone"	,"default:paper"				,"default:stone"},
	}
})

minetest.register_alias("shieldblockstone"	,"lunodecor:shieldblock_stone")
minetest.register_alias("pedraescudo"			,"lunodecor:shieldblock_stone")

--##################################################################################################################

minetest.register_node("lunodecor:ghostblock_stone", {
	description = "Pedra Fantasma",
	tiles = {"default_stone.png"},
	inventory_image = minetest.inventorycube("default_stone.png^text_ghostblock.png"),
	sounds = default.node_sound_stone_defaults(),
	drop = 'lunodecor:ghostblock_stone',
	groups = {cracky=3},
	after_place_node = function(pos, placer)
		local meta = minetest.get_meta(pos)
		meta:set_string("owner", placer:get_player_name() or "")
		--meta:set_string("infotext", "Ampola Vazia")
	end,
})

minetest.register_node("lunodecor:ghostblock_stone_intangible", {
	description = "Pedra Fantasma",
	tiles = {"default_stone.png^text_ghostblock.png"},
	inventory_image = minetest.inventorycube("default_stone.png^text_ghostblock.png"),
	sounds = default.node_sound_stone_defaults(),
	drop = 'lunodecor:ghostblock_stone',
	drawtype = "glasslike",
	paramtype = "light",
	paramtype2 = "flowingliquid",
	sunlight_propagates = true,
	walkable = false,
	alpha = WATER_ALPHA,
	groups = {cracky=3, stone=1, not_in_creative_inventory=1},
})

minetest.register_craft({
	output = 'lunodecor:ghostblock_stone',
	recipe = {
		{"default:stone"				,"default:obsidian_glass"	,"default:stone"},
		{"default:obsidian_glass"	,"lunorecipes:magicdust"	,"default:obsidian_glass"},
		{"default:stone"				,"default:obsidian_glass"	,"default:stone"},
	}
})

minetest.register_alias("ghostblockstone"	,"lunodecor:ghostblock_stone")
minetest.register_alias("pedrafantasma"	,"lunodecor:ghostblock_stone")

--##################################################################################################################

minetest.register_node("lunodecor:ghostblock_stonebrick", {
	description = "Alvenaria de Pedra Fantasma",
	tiles = {"default_stone_brick.png"},
	inventory_image = minetest.inventorycube("default_stone_brick.png^text_ghostblock.png"),
	sounds = default.node_sound_stone_defaults(),
	drop = 'lunodecor:ghostblock_stonebrick',
	groups = {cracky=3},
	after_place_node = function(pos, placer)
		local meta = minetest.get_meta(pos)
		meta:set_string("owner", placer:get_player_name() or "")
		--meta:set_string("infotext", "Ampola Vazia")
	end,
})

minetest.register_node("lunodecor:ghostblock_stonebrick_intangible", {
	description = "Alvenaria de Pedra Fantasma",
	tiles = {"default_stone_brick.png^text_ghostblock.png"},
	inventory_image = minetest.inventorycube("default_stone_brick.png^text_ghostblock.png"),
	sounds = default.node_sound_stone_defaults(),
	drop = 'lunodecor:ghostblock_stonebrick',
	drawtype = "glasslike",
	paramtype = "light",
	paramtype2 = "flowingliquid",
	sunlight_propagates = true,
	walkable = false,
	alpha = WATER_ALPHA,
	groups = {cracky=3, stone=1, not_in_creative_inventory=1},
})

minetest.register_craft({
	output = 'lunodecor:ghostblock_stonebrick',
	recipe = {
		{"default:stonebrick"		,"default:obsidian_glass"	,"default:stonebrick"},
		{"default:obsidian_glass"	,"lunorecipes:magicdust"	,"default:obsidian_glass"},
		{"default:stonebrick"		,"default:obsidian_glass"	,"default:stonebrick"},
	}
})

minetest.register_alias("ghostblockstonebrick"			,"lunodecor:ghostblock_stonebrick")
minetest.register_alias("alvenariadepedrafantasma"		,"lunodecor:ghostblock_stonebrick")

--##################################################################################################################

minetest.register_node("lunodecor:lightsensitive", {
	description = "Lampada de Presenca",
	
	drawtype = "glasslike",
	tiles = {"tex_light_off.png"},
	inventory_image = minetest.inventorycube("tex_light_on.png^tex_eye.png"),
	paramtype = "light",
	is_ground_content = false,
	groups = {cracky=3,oddly_breakable_by_hand=3},
	sounds = default.node_sound_glass_defaults(),
	drop = 'lunodecor:lightsensitive',

	after_place_node = function(pos, placer)
		local meta = minetest.get_meta(pos)
		meta:set_string("owner", placer:get_player_name() or "")
		--meta:set_string("infotext", "Ampola Vazia")
	end,
})

minetest.register_node("lunodecor:lightsensitive_on", {
	description = "Lampada de Presenca",
	drawtype = "glasslike",
	tiles = {"tex_light_on.png"},
	--inventory_image = minetest.inventorycube("tex_light_on.png^tex_eye.png"),
	paramtype = "light",
	sunlight_propagates = true,
	light_source = LIGHT_MAX,
	is_ground_content = false,
	groups = {cracky=3,oddly_breakable_by_hand=3, not_in_creative_inventory=1},
	sounds = default.node_sound_glass_defaults(),
	drop = 'lunodecor:lightsensitive',
})


minetest.register_craft({
	output = 'lunodecor:lightsensitive',
	recipe = {
		{"default:glass"				,"default:obsidian_glass"	,"default:glass"},
		{"default:obsidian_glass"	,"lunorecipes:magicdust"	,"default:obsidian_glass"},
		{"default:glass"				,"default:obsidian_glass"	,"default:glass"},
	}
})

minetest.register_alias("lightsensitive"		,"lunodecor:lightsensitive")
minetest.register_alias("lampadadepresenca"	,"lunodecor:lightsensitive")

--##################################################################################################################

minetest.register_abm({
	nodenames = {
		"lunodecor:shieldblock_stone"			, "lunodecor:shieldblock_stone_tangible", 
		"lunodecor:ghostblock_stone"			, "lunodecor:ghostblock_stone_intangible", 
		"lunodecor:ghostblock_stonebrick"	, "lunodecor:ghostblock_stonebrick_intangible",
		"lunodecor:lightsensitive"				, "lunodecor:lightsensitive_on"
	},
	interval = 1.0,
	chance = 1,
	action = function(pos)
		--print("minetest.env:get_node(pos).name="..minetest.env:get_node(pos).name)
		local meta = minetest.get_meta(pos)
		local ownername = meta:get_string("owner")
		if ownername~=nil and type(ownername)=="string" and ownername~="" then
			local ownerplayer = minetest.env:get_player_by_name(ownername)
			if ownerplayer~=nil and ownerplayer:is_player() then
				local b = pos
				local p = ownerplayer:getpos()
				local dist = ((p.x-b.x)^2 + (p.y-b.y)^2 + (p.z-b.z)^2)^0.5
				--print("dist="..dist)
				if dist <=6 then
					if minetest.env:get_node(pos).name == "lunodecor:shieldblock_stone" then
						minetest.env:add_node(pos, {name="lunodecor:shieldblock_stone_tangible"})
						local meta = minetest.get_meta(pos)
						meta:set_string("owner", ownername)
					end
					if minetest.env:get_node(pos).name == "lunodecor:ghostblock_stone" then
						minetest.env:add_node(pos, {name="lunodecor:ghostblock_stone_intangible"})
						local meta = minetest.get_meta(pos)
						meta:set_string("owner", ownername)
					end
					if minetest.env:get_node(pos).name == "lunodecor:ghostblock_stonebrick" then
						minetest.env:add_node(pos, {name="lunodecor:ghostblock_stonebrick_intangible"})
						local meta = minetest.get_meta(pos)
						meta:set_string("owner", ownername)
					end
					if minetest.env:get_node(pos).name == "lunodecor:lightsensitive" then
						minetest.env:add_node(pos, {name="lunodecor:lightsensitive_on"})
						local meta = minetest.get_meta(pos)
						meta:set_string("owner", ownername)
					end
				else
					if minetest.env:get_node(pos).name == "lunodecor:shieldblock_stone_tangible" then
						minetest.env:add_node(pos, {name="lunodecor:shieldblock_stone"})
						local meta = minetest.get_meta(pos)
						meta:set_string("owner", ownername)
					end
					if minetest.env:get_node(pos).name == "lunodecor:ghostblock_stone_intangible" then
						minetest.env:add_node(pos, {name="lunodecor:ghostblock_stone"})
						local meta = minetest.get_meta(pos)
						meta:set_string("owner", ownername)
					end
					if minetest.env:get_node(pos).name == "lunodecor:ghostblock_stonebrick_intangible" then
						minetest.env:add_node(pos, {name="lunodecor:ghostblock_stonebrick"})
						local meta = minetest.get_meta(pos)
						meta:set_string("owner", ownername)
					end
					if minetest.env:get_node(pos).name == "lunodecor:lightsensitive_on" then
						minetest.env:add_node(pos, {name="lunodecor:lightsensitive"})
						local meta = minetest.get_meta(pos)
						meta:set_string("owner", ownername)
					end
				end
			else --else if ownerplayer~=nil and ownerplayer:is_player() then
				if minetest.env:get_node(pos).name == "lunodecor:shieldblock_stone_tangible" then
					minetest.env:add_node(pos, {name="lunodecor:shieldblock_stone"})
					local meta = minetest.get_meta(pos)
					meta:set_string("owner", ownername)
				end
				if minetest.env:get_node(pos).name == "lunodecor:ghostblock_stonebrick_intangible" then
					minetest.env:add_node(pos, {name="lunodecor:ghostblock_stonebrick"})
					local meta = minetest.get_meta(pos)
					meta:set_string("owner", ownername)
				end
				if minetest.env:get_node(pos).name == "lunodecor:ghostblock_stonebrick_intangible" then
					minetest.env:add_node(pos, {name="lunodecor:ghostblock_stonebrick"})
					local meta = minetest.get_meta(pos)
					meta:set_string("owner", ownername)
				end
				if minetest.env:get_node(pos).name == "lunodecor:lightsensitive_on" then
					minetest.env:add_node(pos, {name="lunodecor:lightsensitive"})
					local meta = minetest.get_meta(pos)
					meta:set_string("owner", ownername)
				end
			end
		end
	end,
})
